#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
try:
    from util.logger import warn_log
except IOError, e:
    logpath = os.path.join(os.getcwd(), 'log')
    os.mkdir(logpath)
    from util.logger import warn_log

try:
    from odbc_p.mysql import MYSQL
except Exception, e:
    warn_log().warning(e.message)

try:
    from odbc_p.mssql import MSSQL
    from odbc_p.access import ACCESS
except Exception, e:
    warn_log().warning(e.message)

try:
    from odbc_p.oracle import ORACLE
except Exception, e:
    warn_log().warning(e.message)

try:
    from odbc_p.firebird import FIREBIRD
except Exception, e:
    warn_log().warning(e.message)


def loader(connect_info):
    db_type = connect_info.get('type', None)
    if db_type == 'MYSQL':
        return MYSQL(connect_info)
    elif db_type == 'MSSQL':
        return MSSQL(connect_info)
    elif db_type == 'ORACLE':
        return ORACLE(connect_info)
    elif db_type == 'MSSQL WIN AUTH':
        return MSSQL(connect_info)
    elif db_type == 'ACCESS':
        return ACCESS(connect_info)
    elif db_type == 'FIREBIRD':
        return FIREBIRD(connect_info)
    elif db_type == 'ODBC':
        return MSSQL(connect_info)
    else:
        return None
